package ssm.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import ssm.dao.UserDao;
import ssm.entity.User;

@Component
public class InstantiationTracingBeanPostProcessor implements ApplicationListener<ContextRefreshedEvent> {
    
    @Autowired
    UserDao userDao;
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if(event.getApplicationContext().getParent() == null){
            System.out.println("启动执行");
            User user = userDao.selectUser("4028b88166eeabf50166eead168f0000");
            System.out.println(user.getName());
        }

//需要执行的逻辑代码，当spring容器初始化完成后就会执行该方法。
    }
}